package org.example.new_hbps_backend_reconstruction.controller.patient;

import com.alibaba.fastjson.JSONObject;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.example.new_hbps_backend_reconstruction.common.results.R;
import org.example.new_hbps_backend_reconstruction.service.WebsocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * <h3>patient</h3>
 *
 * @author HuangJiayu
 * @description <p>基于websocket实现实时对话</p>
 * @date 2024-07-11 15:38
 **/
@RequestMapping("/msg")
@RestController
@Tag(description = "websocket msg", name = "websocket 信息")
public class WebsocketController {

    @Autowired
    private WebsocketService websocketService;

    //TODO:后续完善@Inner注解
    //@Inner(value = false)
    @PostMapping("send")
    public R sendMsg(@RequestBody JSONObject jsonObject) {
        String msg = jsonObject.getString("msg");
        String userName = jsonObject.getString("userName");
        if (websocketService.sendMsg(userName, msg)) {
            return R.ok();
        } else {
            return R.failed();
        }
    }
}